package com.atguigu.tingshu.album.api;

import com.alibaba.fastjson2.JSONObject;
import com.atguigu.tingshu.album.mapper.BaseCategory1Mapper;
import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.BaseAttribute;
import com.atguigu.tingshu.model.album.BaseCategory1;
import com.atguigu.tingshu.model.album.BaseCategory3;
import com.atguigu.tingshu.model.album.BaseCategoryView;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Tag(name = "分类管理")
@RestController
@RequestMapping(value="/api/album/category")
@SuppressWarnings({"unchecked", "rawtypes"})
public class BaseCategoryApiController {
	
	@Autowired
	private BaseCategoryService baseCategoryService;
	@Autowired
	private BaseCategory1Mapper baseCategory1Mapper;
	//创建专辑时获取分类列表
	@Operation(summary = "获取分类列表")
	@GetMapping("getBaseCategoryList")
	public Result findAll(){
		List<JSONObject> baseCategoryList = baseCategoryService.getBaseCategoryList();
		return Result.ok(baseCategoryList);
	}

	@Operation(summary = "根据一级分类获取专辑属性")
	@GetMapping("findAttribute/{categoryId}")
	public Result findAttribute(@PathVariable("categoryId") Integer categoryId) {

		List<BaseAttribute> list = baseCategoryService.findAttribute(categoryId);
		return Result.ok(list);
	}
	// 获取一级分类id查询三级级分类列表
	// http://127.0.0.1:8500/api/album/category/findTopBaseCategory3/3
	// 查询前7个
	@Operation(summary = "根据一级分类id查询三级分类列表数据")
	@GetMapping("findTopBaseCategory3/{c1Id}")
	public Result<List<BaseCategory3>> findTopBaseCategory3(@PathVariable("c1Id") Long c1Id) {
		List<BaseCategory3> list = baseCategoryService.findCategory3ListBycategory1Id(c1Id);
		return Result.ok(list);
	}

	// 根据一级分类查询全部的分类信息
	//  http://127.0.0.1:8500/api/album/category/getBaseCategoryList/1
	@Operation(summary = "根据一级分类查询全部的分类信息")
	@GetMapping("getBaseCategoryList/{c1Id}")
	public Result getBaseCategoryList(@PathVariable("c1Id") Long c1Id) {
		JSONObject jsonObject = baseCategoryService.getBaseCategoryListByc1(c1Id);
		return Result.ok(jsonObject);
	}


	// 远程调用接口 根据三级分类id获取分类视图对象
	// /api/album/category/getCategoryView/{category3Id}
	@Operation(summary = "根据三级分类id获取分类视图对象")
	@GetMapping("getCategoryView/{category3Id}")
	public Result<BaseCategoryView> getBaseCategoryViewByCategory3Id(@PathVariable("category3Id") Long category3Id) {
		BaseCategoryView baseCategoryView = baseCategoryService.getBaseCategoryViewByCategory3Id(category3Id);
		return Result.ok(baseCategoryView);
	}

	// 远程调用 根据一级分类id查询三级分类列表
	// /api/album/category/findCategory3ListBycategory1Id/{c1Id}
	@Operation(summary = "根据一级分类id查询三级分类列表")
	@GetMapping("findCategory3ListBycategory1Id/{c1Id}")
	public Result<List<BaseCategory3>> findCategory3ListBycategory1Id(@PathVariable("c1Id") Long c1Id) {
		List<BaseCategory3> list = baseCategoryService.findCategory3ListBycategory1Id(c1Id);
		return Result.ok(list);
	}

	// 远程调用获取所有的一级分类列表
	// /api/album/category/getBaseCategory1List
	@Operation(summary = "获取所有的一级分类列表")
	@GetMapping("getBaseCategory1List")
	public Result<List<Long>> getBaseCategory1List() {
		List<BaseCategory1> baseCategory1List = baseCategory1Mapper.selectList(null);
		List<Long> list = baseCategory1List.stream().map(BaseCategory1::getId).toList();
		return Result.ok(list);
	}

}

